<template>
  <div v-if="props.readonly&&props.readonly==1">{{name_format}}</div>
  <el-select v-else v-model="name" placeholder="请选择" clearable filterable :multiple="props.multiple==1">
    <el-option v-for="item in options" :key="item.tagid" :label="item.tagname" :value="item.tagid" />
  </el-select>
</template>

<script setup lang="ts">
const { proxy } = getCurrentInstance();
//counter
import useCounterStore from "@/store/counter";
const counter = useCounterStore();

let props = defineProps(["modelValue", "multiple", "readonly"]);
const emit = defineEmits(["update:modelValue"]);

let options = ref([]);

onMounted(() => {
  getInfo();
});

let name_format = computed(() => {
  let current;
  for (let index = 0; index < options.value.length; index++) {
    const element = options.value[index];
    if (element.tagid == props.modelValue) current = index;
  }
  return current >= 0 ? options.value[current].tagname : "";
});

const name = computed({
  get() {
    return props.modelValue;
  },
  set(value: String) {
    emit("update:modelValue", value);
  },
});

async function getInfo() {
  let resp = await proxy.$apis.moxueyuanTags({ type: "list" });
  resp.forEach((element) => {
    if (element.tagid) options.value.push(element);
  });
}
</script>



<style lang="scss" scoped>
.container {
}
</style>






